package TenkindsOfAlgorithm.patternMatch;
/**
 * 暴力匹配  最low的 时间复杂度为O(n*m) 1
 */
public class bruteForce {
    public static void main(String[] args) {
        String s1 = "abababc";
        String s2 = "abc";
        System.out.println(bf(s1, s2));
    }
    public static int bf(String a,String b){
        char[] str = a.toCharArray();
        char[] s = b.toCharArray();
        for (int i = 0; i < str.length; i++) {
            for (int j = 0; j < s.length; ) {
                if (str[i]==s[j]){
                    i++;
                    j++;
                }else {
                    i = i-j+1;
                    j = 0;
                }
                if (j==s.length-1 && str[i]==s[j]){
                    return i-j+1;
                }
            }

        }
        return -1;
    }
}
